package test.dequeue;

public class Solution {

    static public void reverseWords(char[] s) {
        //在此处写入代码

        int beginIndex = 0; //前端字符串开始位置索引
        int endIndex = s.length - 1 ;
        for (int i = 0; i< s.length - 1 -i; i++) {
            char begin = s[i];
            char end = s[s.length - 1 - i];
            if (begin != ' ') {
                for (int j = s.length - 1 - i; j < endIndex; j ++) {
                    s[j] = s[j+1];
                }
                s[endIndex] = begin;
            } else {
                s[s.length - 1 - i] = begin;
                endIndex = s.length - 2 - i;
            }
            System.out.println(begin);
            System.out.println(s);
            System.out.println(end);
            if (end != ' ') {
                for (int j = i; j > beginIndex; j --) {
                    s[j] = s[j-1];
                }
                s[beginIndex] = end;
            } else {
                s[i] = end;
                beginIndex = i + 1;
            }
            System.out.println(s);
        }


    }

    public static void main(String[] args) {
        char[] chars = new char[] {'t','h','e',' ','c','h','h','a','l','k',' ','i','s',' ','b','l','u','e'};
       // char[] chars = new char[] {'t','h','e',' ','s','k','y',' ','i','s',' ','b','l','u','e'} ;
        reverseWords(chars);
    }
}
